<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('电话操作记录列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            操作人：<input type="text" name="opUserName"/>
                        </li>
                        <li>
                            <input type="hidden" name="sbDeptName"/>
                        </li>
                        <li class="select-time">
                            <label>操作时间： </label>
                            <input type="text" class="time-input mr10" id="startTime1" placeholder="开始时间"
                                   name="beginTime"/>
                            <input type="text" class="time-input" id="endTime1" placeholder="结束时间"
                                   name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>

        </div>
<!--        <div class="btn-group-sm " id="toolbar" role="group">-->
<!--            <a class="btn btn-info" onclick="exTelExcel()">-->
<!--                <i class="fa fa-download"></i> 导出-->
<!--            </a>-->
<!--        </div>-->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "system/lookup";

    $(function () {
        var options = {
            url: prefix + "/telLogListJson/",
            detailUrl:  "/system/mTelWF/forShow/logDetail/{id}",
            sortName: "WfId desc,logId",
            sortOrder: "desc",
            uniqueId: "myPkVal",
            modalName: "历史处理记录",
            columns: [
                {field:'myPkVal',title:'流水号',visible:false},
                {field:'WfId',title:'WfId',visible:false},
                {field:'OpUserName',title:'操作人',align:'center',sortable:false},
                {field:'OpDeptName',title:'操作部门',align:'center',sortable:false},
                {field:'opTime',title:'操作时间',align:'center',sortable:false},
                {field:'OpAction',title:'动作',align:'center'},
                {field:'OpDesc',title:'操作简述',align:'center',width:420,
                    formatter:function (value, row, index){
                    if(value==undefined){
                        value='-'
                    }
                        return "<span style='cursor: pointer;' title='"+value+"'>"+value+"</span>"
                    },
                    cellStyle: cellEllipsis},
                {field:'WsOpen',title:'公开',align:'center',sortable:true,formatter:function(value,row,index){return fmtWFormOpen(value,row,index);}},
                {field:'WsDesc',title:'公开内容',align:'center',width:110},
                {
                    title: '操作',
                    align: 'center',
                    visible: false,
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.myPkVal + '\')"><i class="fa fa-edit"></i>详情</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="updateOpen(\'' + row.myPkVal + '\')"><i class="fa fa-remove"></i>切换公开</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //切换公开状态
    function updateOpen(pkValue){
        $.ajax({
            type: "post",
            url: "/system/mTelWF/forShow/updateState/" + pkValue,
            success: function(){
                $.modal.msgSuccess("切换成功");
                $.table.refresh();
            }
        });
    }
    function reset() {
        $.form.reset();
        setDefaultTime();
    }
    //导出操作记录
    // function exTelExcel(){
    //     let exURL = prefix + "/TelWFLog/export";
    //     var data = $("#post-form").serializeArray();
    //     $.modal.confirm("确定导出电话工单操作记录数据吗？", function() {
    //         $.modal.loading("正在导出数据，请稍候...");
    //         $.post(exURL,data,function(result) {
    //             if (result.code == web_status.SUCCESS) {
    //                 window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
    //             } else if (result.code == web_status.WARNING) {
    //                 $.modal.alertWarning(result.msg)
    //             } else {
    //                 $.modal.alertError(result.msg);
    //             }
    //             $.modal.closeLoading();
    //         });
    //     });
    // }
    //设置默认日期
    function setDefaultTime(){
        var time = new Date();
        var day = ("0" + time.getDate()).slice(-2);
        var month = ("0" + (time.getMonth() + 1)).slice(-2);
        var year=time.getFullYear();
        var today = time.getFullYear() + "-" + (month) + "-" + (day);
        $('#endTime1').val(today);
        var monthNum=1; //要减的月数()自己定义
        var year2 = year;
        var month2 = parseInt(month) - monthNum;
        if (month2 <=0) {
            year2 = parseInt(year2) - parseInt(month2 / 12 == 0 ? 1 : parseInt(month2) / 12);
            month2 = 12 - (Math.abs(month2) % 12);
        }
        var day2 = day;
        var days2 = new Date(year2, month2, 0);
        days2 = days2.getDate();
        if (day2 > days2) {
            day2 = days2;
        }
        if (month2 < 10) {
            month2 = '0' + month2;
        }
        var t2 = year2 + '-' + month2 + '-' + day2;
        $('#startTime1').val(t2);
    }
    $(document).ready(function() {
        // 显示默认日期
        setDefaultTime();
    })

    // laydate 时间控件绑定
    layui.use('laydate', function() {
        var laydate = layui.laydate;
            var startDate = laydate.render({
                elem: '#startTime1',
                max: $('#endTime1').val(),
                min:getMinStartTime(),
                theme: 'molv',
                type: $('#startTime1').attr("data-type") || 'date',
                trigger: 'click',
                done: function(value, date) {
                    // 结束时间大于开始时间
                    if (value !== '') {
                        endDate.config.min.year = date.year;
                        endDate.config.min.month = date.month - 1;
                        endDate.config.min.date = date.date;
                    } else {
                        endDate.config.min.year = '';
                        endDate.config.min.month = '';
                        endDate.config.min.date = '';
                    }
                }
            });
        var endDate = laydate.render({
            elem: '#endTime1',
            min: $('#startTime1').val(),
            theme: 'molv',
            type: $('#endTime1').attr("data-type") || 'date',
            trigger: 'click',
            done: function(value, date) {
                if (value !== '') {
                    var minStartTime = getMinStartTime();
                    var strings = minStartTime.split('-');
                    var year = strings[0];
                    var month = strings[1];
                    var day = strings[2];
                    var month1=month.replace(/^0/,"");
                    var day1=day.replace(/^0/,"");
                    startDate.config.min.year = year;
                    startDate.config.min.month = month1 - 1;
                    startDate.config.min.date = day1;

                    startDate.config.max.year = date.year;
                    startDate.config.max.month = date.month - 1;
                    startDate.config.max.date = date.date;
                    console.log(startDate.config.min);
                } else {
                    startDate.config.max.year = '2099';
                    startDate.config.max.month = '12';
                    startDate.config.max.date = '31';
                }
            }
        });
    });
    //获取开始时间的最小时间min
    function getMinStartTime(){
        var val = $("#endTime1").val();
        if(val==undefined){
            var time = new Date();
            time.setTime(time.getTime());
            val= time.getFullYear()+"-" + (time.getMonth()+1) + "-" + time.getDate();
        }
        var monthNum=1; //要减的月数(1)自己定义
        var dateArr = val.split('-'); //s2当前时间
        var year = dateArr[0]; //获取当前日期的年份
        var month = dateArr[1]; //获取当前日期的月份
        var day = dateArr[2]; //获取当前日期的日
        var days = new Date(year, month, 0);
        days = days.getDate(); //获取当前日期中月的天数
        var year2 = year;
        var month2 = parseInt(month) - monthNum;
        if (month2 <=0) {
            year2 = parseInt(year2) - parseInt(month2 / 12 == 0 ? 1 : parseInt(month2) / 12);
            month2 = 12 - (Math.abs(month2) % 12);
        }
        var day2 = day;
        var days2 = new Date(year2, month2, 0);
        days2 = days2.getDate();
        if (day2 > days2) {
            day2 = days2;
        }
        if (month2 < 10) {
            month2 = '0' + month2;
        }
        var t2 = year2 + '-' + month2 + '-' + day2;
        return t2;
    }




</script>
</body>
</html>